package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import user.User;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JButton;


public class ServiceFrame extends JFrame {

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					User tempUser = new User("fac1");
					ServiceFrame frame = new ServiceFrame(tempUser);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	private static final long serialVersionUID = 1L;

	private User currUser;
	
	private JPanel contentPane;
	private JRadioButton registerCrsRdBttn;
	private JPanel panel_0;
	private JPanel panel_1;
	private JPanel panel_2;
	private JPanel panel_3;
	private JPanel panel_4;
	private JPanel panel_5;
	private JPanel panel_6;
	private JPanel panel_7;
	private JPanel panel_8;
	private JPanel panel_9;
	private JRadioButton findTutorsRdBttn;
	private JRadioButton updatePInfoRdBttn;
	private JRadioButton tutorRdBttn;
	private JRadioButton gradePatRdBttn;
	private ButtonGroup studentBttnGroup;
	private JButton nextBttn;
	private JButton logoutBttn;

	private JRadioButton viewStudentPerfRdBttn;

	private JRadioButton assignTutorsRdBttn;

	private JRadioButton assignGradesRdBttn;

	private ButtonGroup instBttnGroup;

	/**
	 * Create the frame.
	 */
	public ServiceFrame(User currUser) {
	
		this.currUser = currUser;
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 700, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new GridLayout(5, 2, 0, 0));
		setContentPane(contentPane);
		
		panel_0 = new JPanel();
		contentPane.add(panel_0);
		
		panel_1 = new JPanel();
		contentPane.add(panel_1);
		
		logoutBttn = new JButton("Logout");
		panel_1.add(logoutBttn);
		
		panel_2 = new JPanel();
		contentPane.add(panel_2);
			
		panel_3 = new JPanel();
		contentPane.add(panel_3);
		
		panel_4 = new JPanel();
		contentPane.add(panel_4);
		
		panel_5 = new JPanel();
		contentPane.add(panel_5);
		
		panel_6 = new JPanel();
		contentPane.add(panel_6);
		
		panel_7 = new JPanel();
		contentPane.add(panel_7);
		
		panel_8 = new JPanel();
		contentPane.add(panel_8);
		
		panel_9 = new JPanel();
		contentPane.add(panel_9);
		
		nextBttn = new JButton("Next");
		panel_9.add(nextBttn);
		nextBttn.addActionListener(nextListener);
		
		if(currUser.isStudent()) {
			setupStudent();
		}
		else 
			setupInstructor();
	}
	//--------------------------------------------------------------------------------------------------------------
	
	/**
	 * setup Student GUI
	 */
	private void setupStudent() {
		registerCrsRdBttn = new JRadioButton("Register for Courses");
		panel_0.add(registerCrsRdBttn);
		registerCrsRdBttn.setSelected(true);
		
		updatePInfoRdBttn = new JRadioButton("Update Personal Information");
		panel_2.add(updatePInfoRdBttn);
	
		findTutorsRdBttn = new JRadioButton("Find Tutors");
		panel_4.add(findTutorsRdBttn);
		
		tutorRdBttn = new JRadioButton("Tutor Logbook");
		panel_6.add(tutorRdBttn);
		
		gradePatRdBttn = new JRadioButton("View Grading Pattern");
		panel_8.add(gradePatRdBttn);
		
		studentBttnGroup = new ButtonGroup();
		studentBttnGroup.add(findTutorsRdBttn);
		studentBttnGroup.add(gradePatRdBttn);
		studentBttnGroup.add(registerCrsRdBttn);
		studentBttnGroup.add(tutorRdBttn);
		studentBttnGroup.add(updatePInfoRdBttn);
	}
	//-----------------------------------------------------------------------------------------------------
	
	/**
	 * setup Instructor GUI
	 */
	private void setupInstructor() {
		assignGradesRdBttn = new JRadioButton("Assign Grades");
		panel_0.add(assignGradesRdBttn);
		assignGradesRdBttn.setSelected(true);
		
		updatePInfoRdBttn = new JRadioButton("Update Personal Information");
		panel_2.add(updatePInfoRdBttn);
	
		assignTutorsRdBttn = new JRadioButton("Assign Tutors");
		panel_4.add(assignTutorsRdBttn);
		
		viewStudentPerfRdBttn = new JRadioButton("View Student Performance");
		panel_6.add(viewStudentPerfRdBttn);
		
		instBttnGroup = new ButtonGroup();
		instBttnGroup.add(assignGradesRdBttn);
		instBttnGroup.add(updatePInfoRdBttn);
		instBttnGroup.add(assignTutorsRdBttn);
		instBttnGroup.add(viewStudentPerfRdBttn);
	}
	//---------------------------------------------------------------------------------------------------------

	
///////////////////////////////////////////////////////////////////////////////////////
// BUTTON LISTENERS
///////////////////////////////////////////////////////////////////////////////////////
	
	private ActionListener nextListener = new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			if (currUser.isStudent()) {
				if(registerCrsRdBttn.isSelected()){
					System.out.println("Register");
					StudentDeptSelect regFrame = new StudentDeptSelect(currUser);
					regFrame.setVisible(true);
					ServiceFrame.this.dispose();
				}
				else if (updatePInfoRdBttn.isSelected()) {
					System.out.println("P Info");
					PersonalInformationFrame regFrame = new PersonalInformationFrame(currUser);
					regFrame.setVisible(true);
					ServiceFrame.this.dispose();
				}
				else if (findTutorsRdBttn.isSelected()) {
					System.out.println("Find Tutors");
				}
				else if (gradePatRdBttn.isSelected()) {
					System.out.println("Grade Pattern");
				}
				else if (tutorRdBttn.isSelected()) {
					System.out.println("Tutor Logbook");
				}
			}
			else {  // currUser.isFaculty()
				if(assignGradesRdBttn.isSelected()){
					System.out.println("Assign Grades");
				}
				else if (updatePInfoRdBttn.isSelected()) {
					System.out.println("P Info");
					PersonalInformationFrame regFrame = new PersonalInformationFrame(currUser);
					regFrame.setVisible(true);
					ServiceFrame.this.dispose();
				}
				else if (assignTutorsRdBttn.isSelected()) {
					System.out.println("Assign Tutors");
				}
				else if (viewStudentPerfRdBttn.isSelected()) {
					System.out.println("Student performance");
				}

			}
				
		}
		
	};
	

	
}
